Code Related To Single-Shot, Maskless, and Reliable Lensless X-Ray Imaging with Structured Illumination
----------------

Disclaimer: This collection of code contains parts of a computational package, "CDTools" designed for automatic differentiation ptychography. The details of this code package have not yet been reported in the literature, and while of course it is reasonable to inspect it insofar as the code therein relates to the conclusions in this paper, we ask you respect the pre-publication nature of this code package and contact us if you are interested in using any portion of it for ptychographic reconstructions.


Preequisites
============

In order to run the scripts contained in this folder, a working python 3 installation is needed with the following dependencies:

* numpy
* scipy
* matplotlib
* pytorch
* numba
* h5py
* python-dateutil

In addition, it is highly recommended that pytorch be built with CUDA support and run on a machine with a GPU to make the calculations tractable.

Organization
============

This folder contains files relating to the three major portions of the paper: the numerical experiments, the optical experiment, and the x-ray experiment. In addition, it includes code to generate optics equivalent to those used in the experiment. The code to perform the ptychographic reconstructions themselves has not been included as these reconstructions are standard.

Numerical Experiments
=====================

The eight files

* run_bandlimiting_trial.py
* run_poisson_trial.py
* run_propagation_trial.py
* run_resolution_trial.py
* run_missingdata_trial.py
* run_example_reconstruction.py
* run_study_uniformity.py
* run_study_uniformity_2.py

Run the various numerical experiments reported in the paper. These should be expected to take between an hour and several days on a single GPU. The file plot_numerical_experiments.py plots the results from all these experiments. An example data file, the output of each numerical experiment, is included in the data folder in the version of this codebase that includes numerical results. Using this data, one can regenerate the figures without rerunning the numerical experiments.


Optical Experiments
===================

The file run_optical_analysis.py performs and plots the RIP reconstructions from the optical experiment. The ptychography reconstruction's results as well as the cxi file for each single diffraction pattern used in an RIP reconstruction are included in the data folder. The original dataset used for the ptychography reconstruction is included in the version of this code that includes experimental data, and is also available on the CXIDB or upon separate request to the authors.


X-Ray Experiments
=================
The file run_xray_analysis.py performs and plots the RIP reconstructions from the optical experiment. The ptychography reconstruction's results as well as the cxi file for each single diffraction pattern used in an RIP reconstruction are included in the data folder. The original dataset used for the ptychography reconstruction is included in the version of this code that includes experimental data, and is also available on the CXIDB or upon separate request to the authors.


Optics Generation
=================

The three files

* generate_optical_zp.py
* generate_xray_zp.py
* generate_example_zp.py

Are used to geneerate a randomized zone plate with the same parameters as those that were used in the optical and x-ray experiments, respectively. The final file was used to genarate an example zone plate to illustrate the principle in the supplement to the paper.


Supporting Files
================

The CDTools package contains tools for opening and writing to .cxi files as well as for manipulating ptychographic data, doing math with complex numbers in pytorch, and plotting results. In addtion, it contains tools for standard analysis methods in CDI, such as calculating Fourier Ring Correlations and performing subpixel shifts.

The Light_Propagation package was used for numerical light propagation during the design of the optics.

The RIP_tools.py file contains functions specifically desined for RIP simulations and reconstructions. This includes the function for performing RIP reconstructions, for performing reconstructions over a defocus ensemble, and for generating simulated band-limited-random probes.


Thanks for reading! Please feel free to contact the authors with any questions.